package com.example.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class MyAspect {
    @Pointcut("@annotation(com.example.aspect.MyAop)")
    public void logPointCut() {
    }

    @Around("logPointCut()")
    public Object logAop(ProceedingJoinPoint point) {
        Object proceed = null;
        try {
            log.info("【方法执行前】日志打印输出:{}",point.getSignature().getDeclaringTypeName());
            proceed = point.proceed();
            log.info("【方法执行后】日志打印输出:{}",point.getSignature().getDeclaringTypeName());
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
        return proceed;
    }
}
